<template>
    <div>
        <front-header />
        <div class="knowledge-list-page">
            <div class="page-title">技术知识库</div>
            <el-row :gutter="24">
                <el-col :span="8" v-for="item in list" :key="item.id" class="knowledge-col">
                    <el-card class="knowledge-card" shadow="hover">
                        <el-image v-if="item.imageUrl" :src="getImageUrl(item.imageUrl)" class="knowledge-img"
                            fit="cover" />
                        <div class="knowledge-title">{{ item.title }}</div>
                        <div class="knowledge-summary">{{ item.summary }}</div>
                        <el-button type="success" size="small" @click="goToDetail(item)">
                            查看详情</el-button>
                    </el-card>
                </el-col>
            </el-row>
        </div>
        <front-footer />
    </div>
</template>
<script>
import FrontHeader from '@/components/front/FrontHeader.vue'
import FrontFooter from '@/components/front/FrontFooter.vue'
import { getKnowledgeList } from '@/api/AgricultureKnowledgeController'

/**
 * 农业知识列表组件
 */
export default {
    name: 'AgricultureKnowledgeList',
    components: {
        FrontHeader,
        FrontFooter
    },
    data() {
        return {
            list: [],
            dialogVisible: false,
            detail: {}
        }
    },
    methods: {
        getImageUrl(url) {
            if (!url) return ''
            return url.startsWith('/api') ? url : `/api${url}`
        },

        goToDetail(item) {
            this.$router.push('/front/knowledge/' + item.id)
        }
    },
    mounted() {
        getKnowledgeList().then(res => {
            this.list = res
        })
    }
}
</script>
<style scoped>
/* 优化页面整体布局 */
.knowledge-list-page {
    padding: 48px 32px;
    background: #f9f9f9;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-height: 100%;
    overflow: auto;
}

/* 优化标题样式 */
.page-title {
    font-size: 36px;
    font-weight: 700;
    color: #333333;
    margin-bottom: 48px;
    letter-spacing: 3px;
    position: relative;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

}

.page-title::after {
    content: '';
    position: absolute;
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 4px;
    background: linear-gradient(90deg, #4caf50 0%, #81c784 100%);
    border-radius: 2px;
}

/* 优化知识卡片列 */
.knowledge-col {
    margin-bottom: 40px;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.knowledge-col:hover {
    transform: translateY(-8px);
}

/* 优化知识卡片 */
.knowledge-card {
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    min-height: 360px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    background: #ffffff;
    border: 1px solid #eaeaea;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.knowledge-card:hover {
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.15);
    border-color: #4caf50;
}

/* 优化图片样式 */
.knowledge-img {
    width: 100%;
    height: 220px;
    object-fit: cover;
    border-radius: 12px 12px 0 0;
    margin-bottom: 20px;
    transition: transform 0.3s ease;
    filter: brightness(0.95);
}

.knowledge-card:hover .knowledge-img {
    transform: scale(1.05);
    filter: brightness(1);
}

/* 优化标题和摘要样式 */
.knowledge-title {
    font-size: 22px;
    font-weight: 700;
    color: #333333;
    margin-bottom: 14px;
    margin-top: 4px;
    padding: 0 20px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

.knowledge-summary {
    color: #666666;
    font-size: 16px;
    margin-bottom: 20px;
    flex: 1;
    padding: 0 20px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    line-height: 1.6;
}

/* 优化按钮样式 */
.knowledge-card .el-button {
    align-self: center;
    margin-bottom: 20px;
    border-radius: 24px;
    padding: 8px 24px;
    background: linear-gradient(90deg, #4caf50 0%, #81c784 100%);
    border: none;
    color: white;
    transition: all 0.3s ease;
    font-weight: 500;
}

.knowledge-card .el-button:hover {
    background: linear-gradient(90deg, #3b9c3f 0%, #6ebb71 100%);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

/* 优化响应式布局 */
@media (max-width: 1200px) {
    .el-col {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

@media (max-width: 768px) {
    .el-col {
        flex: 0 0 100%;
        max-width: 100%;
    }
    .knowledge-list-page {
        padding: 32px 16px;
    }
    .page-title {
        font-size: 28px;
    }
}
</style>